//
//  WmcEditWatermarkBrandCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/6/9.
//

import UIKit

class WmcEditWatermarkBrandCell: WmcEditWatermarkBaseCell {
    /// 品牌图
    lazy var brandImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.backgroundColor = .wmc_grayH19_F5F5F5
        imageView.contentMode = .scaleAspectFit
        imageView.layer.cornerRadius = 4
        imageView.layer.masksToBounds = true
        return imageView
    }()

    override func makeUI() {
        addSubview(switchBtn)
        switchBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(Wmc_standardEdge.left)
        }

        addSubview(arrowImageView)
        arrowImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-Wmc_standardEdge.right)
            make.size.equalTo(17)
        }

        titleLabel.font = 14.yp.uiFont(weight: .medium)
        titleLabel.textColor = UIColor.wmc_grayH2_323233
        titleLabel.textAlignment = .left
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.bottom.equalTo(-8)
            make.left.equalTo(switchBtn.snp.right).offset(8)
            make.right.equalTo(arrowImageView.snp.left).offset(-8)
        }

        addSubview(brandImageView)
        brandImageView.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.bottom.equalTo(-8)
            make.right.equalTo(arrowImageView.snp.left).offset(-4)
            make.width.equalTo(70)
        }
        
        addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
            make.left.equalTo(titleLabel.snp_leftMargin)
            make.right.equalTo(arrowImageView.snp_rightMargin)
        }
    }

    override func configModel(_ model: WmcWatermarkOptionModel,
                              styleMode: WmcBaseWatermarkTemplateView.StyleMode,
                              watermarkModel: WmcWatermarkDetailModel) {
        
        let model = model
        titleLabel.text = model.title

        brandImageView.isHidden = true
        switch model.fieldType {
        case .brand:
            brandImageView.kf.setImage(with: model.content.yp.url)
            brandImageView.isHidden = false
        default: break
        }

        switchBtn.isEnabled = model.isAction
        switchBtn.isOn = model.isOpen

        switchBtn.yp.addEvent { [weak self] switc in
            guard let weakSelf = self else { return }
            model.isOpen = switc.isOn
            weakSelf.switchAnctionBlock?(weakSelf.indexPath, model)
        }
    }
}
